<?php
// 获取报修信息
// header("content-type:text/html;charset=utf-8");
include_once("conn.php");
if(!session_id()){
    session_start();
}

//获取一条报修id的所有信息
function get_show_info($fix_id)
{
    global $conn_DB;
    $sql = "SELECT * FROM tb_fixinfo_request WHERE fix_id = '" . $fix_id . "'";
    $result = mysqli_query($conn_DB, $sql);
    if (!$result) {
        die("<script>alert('获取报修信息失败！请重试！');location='r-main.php';</script> ");
    }
    if (mysqli_num_rows($result) == 0) {
        die("<script>alert('该条信息不存在！');location='r-main.php';</script> ");
        // echo $sql;
    }
    $row = mysqli_fetch_assoc($result);
    if ($row['fix_status'] == 0) {
        $status = "等待受理";
    } else if ($row['fix_status'] == 1) {
        $status = "已受理，等待维修";
    } else if ($row['fix_status'] == 2) {
        $status = "维修完成";
    } else {
        $status = "申请取消";
    }
    $i = '';
    if($row['fix_status'] == 1 || $row['fix_status'] == 2){
        $sql_1 = "SELECT *
            FROM tb_fix_repairer
            LEFT JOIN tb_repairer ON tb_fix_repairer.r_id = tb_repairer.r_id
            WHERE tb_fix_repairer. fix_id = '" . $fix_id . "'";
            // echo $sql_1;

        if (!$result_1 = mysqli_query($conn_DB, $sql_1)) {
            die("<script>alert('获取报修信息失败！请重试！');location='r-main.php';</script> ");
        }else{
            $row_1 = mysqli_fetch_assoc($result_1);
            $i = "
            <div class='info-div'>
                <div class='info-div-tope'>
                    维修人姓名：
                </div>
                <div class='info-div-bottom'>
                    " . $row_1['r_name'] . "
                </div>
            </div>
            <div class='info-div'>
                <div class='info-div-tope'>
                    维修人工号：
                </div>
                <div class='info-div-bottom'>
                    " . $row_1['r_id'] . "
                </div>
            </div>
            <div class='info-div'>
                <div class='info-div-tope'>
                    维修人联系电话：
                </div>
                <div class='info-div-bottom'>
                    " . $row_1['r_phone'] . "
                </div>
            </div>
            ";
        }
    }

    if($row['fix_endtime'] == null){
        $endtime = "未完成";
    }
    else{
        $endtime = $row['fix_endtime'];
    }
    echo "
        <div class='fixinfo'>
            <div class='info-div'>
                <div class='info-div-tope'>
                    报修单号：
                </div>
                <div class='info-div-bottom'>
                    " . $row['fix_id'] . "
                </div>
            </div>
            <div class='info-div'>
                <div class='info-div-tope'>
                    报修人：
                </div>
                <div class='info-div-bottom'>
                    " . $row['fix_name'] . "
                </div>
            </div>
            <div class='info-div'>
                <div class='info-div-tope'>
                    联系电话：
                </div>
                <div class='info-div-bottom'>
                    " . $row['fix_phone'] . "
                </div>
            </div>
            <div class='info-div'>
                <div class='info-div-tope'>
                    故障发生区域：
                </div>
                <div class='info-div-bottom'>
                    " . $row['fix_area'] . "
                </div>
            </div>
            <div class='info-div'>
                <div class='info-div-tope'>
                    故障详细地址：
                </div>
                <div class='info-div-bottom'>
                    " . $row['fix_address'] . "
                </div>
            </div>
            <div class='info-div'>
                <div class='info-div-tope'>
                    故障类型：
                </div>
                <div class='info-div-bottom'>
                    " . $row['fix_type'] . "
                </div>
            </div>
            <div class='info-div'>
                <div class='info-div-tope'>
                    故障原因：
                </div>
                <div class='info-div-bottom'>
                    " . $row['fix_reason'] . "
                </div>
            </div>
            <div class='info-div'>
                <div class='info-div-tope'>
                    故障描述：
                </div>
                <div class='info-div-bottom'>
                    " . $row['fix_depicted'] . "
                </div>
            </div>
            <div class='info-div'>
                <div class='info-div-tope'>
                    报修图片：
                </div>
                <div class='info-div-img'>
                    <img src='../img/user_upload/" . $row['fix_img'] . "' alt='图片找不到了QAQ'>
                </div>
            </div>
            <div class='info-div'>
                <div class='info-div-tope'>
                    报修申请日期：
                </div>
                <div class='info-div-bottom'>
                    " . $row['fix_sendtime'] . "
                </div>
            </div>
            <div class='info-div'>
                <div class='info-div-tope'>
                    报修状态：
                </div>
                <div class='info-div-bottom'>
                    " . $status . "
                </div>
            </div>
            ".$i."
            <div class='info-div'>
                <div class='info-div-tope'>
                    报修完成日期：
                </div>
                <div class='info-div-bottom'  style='margin-bottom: 10px;'>
                    " . $endtime . "
                </div>
            </div>
        </div>";
    if ($row['fix_status'] == 2) {
        $sql_feedback = "SELECT * FROM tb_feedback WHERE fix_id = '" . $row['fix_id']. "'";
        $result_feedback = mysqli_query($conn_DB, $sql_feedback);
        if ($result_feedback) {
            echo"
                <div class='feedback-div'>
                    <h4>反馈信息</h4>
                    <hr class='hr-feedback'>
                    <div class='feedback-div-items'>
                        <span style='font-weight: bold;'>反馈状态：</span>
            ";
            if (mysqli_num_rows($result_feedback) == 0) {
                echo"<span>未反馈</span></div>";
            } else {
                $row_feedback = mysqli_fetch_assoc($result_feedback);
                echo"<span>已反馈</span></div>
                    <div class='feedback-div-items'>
                        <span style='font-weight: bold;'>反馈内容：</span>
                        <br>
                        <div class='feedback-content'>". $row_feedback['content'] ."</div>
                    </div>
                ";
            }
        }
    }        
}